import java.io.IOException;
import java.net.*;
import java.util.Scanner;

public class UDPEchUser {
    private DatagramSocket socket;
    private int port;
    private String ServiceIp;
    public UDPEchUser(int port,String serviceIp) throws SocketException {
        this.port=port;
        this.ServiceIp=serviceIp;
        socket=new DatagramSocket();
    }
    public void start() throws IOException {
        while (true) {
            Scanner scanner=new Scanner(System.in);
            String request=scanner.next();
            DatagramPacket requestPacket=new DatagramPacket(request.getBytes(),request.getBytes().length,
                    InetAddress.getByName(ServiceIp),port);
            socket.send(requestPacket);
            DatagramPacket responsePacket=new DatagramPacket(new byte[4096],4096);
            socket.receive(responsePacket);
            String response=new String(responsePacket.getData(),0,responsePacket.getLength());
            System.out.println(response);
        }
    }

    public static void main(String[] args) throws IOException {
        UDPEchUser user=new UDPEchUser(9090,"127.0.0.1");
        user.start();
    }
}
